Completed
Push — master ( 401bbc...02c732 )
by Grant
05:46 queued 02:35
created

JobApplicationAPI.populateApplicationWithJobSeekerProfileContent   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
var JobApplicationAPI = {};
2
3
JobApplicationAPI.ApplicationQuestionAnswer = function (
4
        jobApplicationId,
5
        jobPosterQuestionId,
6
        question,
7
        answer) {
8
    this.job_poster_application_id = jobApplicationId;
9
    this.job_poster_question_id = jobPosterQuestionId;
10
    this.question = question;
11
    this.answer = answer;
12
};
13
14
/*
15
 * It's recommended to use the costructor for this object, to avoid dealing
16
 * directly with multilevel JSON
17
 *
18
 * @return {JobApplicationAPI.JobApplication}
19
 */
20
JobApplicationAPI.JobApplication = function (
21
        jobApplicationId,
22
        jobPosterId,
23
        userId,
24
        jobApplicationStatusId,
25
        applicationQuestionAnswers) {
26
    this.job_poster_application = {};
27
    this.job_poster_application.job_poster_application_id = jobApplicationId;
28
    this.job_poster_application.application_job_poster_id = jobPosterId;
29
    this.job_poster_application.user_id = userId;
30
    this.job_poster_application.job_poster_application_status_id = jobApplicationStatusId;
31
32
    this.application_question_answers = applicationQuestionAnswers;
33
};
34
35
JobApplicationAPI.showCreateJobApplication = function (jobPosterId) {
36
    if (!UserAPI.hasSessionUser()) {
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
37
        //TODO: this page should not be accessible if not logged in
38
        window.alert("You must log in before submitting a job application.");
39
        return;
40
    }
41
42
    document.getElementById("jobApplicationJobPosterId").value = jobPosterId
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
43
44
    var stateInfo = {pageInfo: 'job_application', pageTitle: 'Talent Cloud: Job Application'};
45
    document.title = stateInfo.pageTitle;
46
    history.pushState(stateInfo, stateInfo.pageInfo, '#JobApplication/' + jobPosterId);
0 ignored issues
show
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
47
48
    TalentCloudAPI.hideAllContent();
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
49
    window.scrollTo(0, 0);
50
51
    var createJobApplicationSection = document.getElementById('createJobApplicationSection');
52
    createJobApplicationSection.classList.remove('hidden');
53
54
    JobApplicationAPI.showApplicationSection("my-information", jobPosterId);
55
56
    var locale = TalentCloudAPI.getLanguageFromCookie();
57
58
    // document.getElementById('jobApplicationJobPosterId').value = jobPosterId;
59
60
    if (UserAPI.hasSessionUser()) {
61
        var user = UserAPI.getSessionUserAsJSON();
62
        var applicantProfilePic = document.getElementById('createJobApplicationProfilePic');
63
        ProfilePicAPI.refreshProfilePic(user.user_id, applicantProfilePic);
0 ignored issues
show
Bug introduced by
The variable ProfilePicAPI seems to be never declared. If this is a global, consider adding a /** global: ProfilePicAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
64
        JobApplicationAPI.populateApplicationWithUserContent(user);
65
    }
66
67
    DataAPI.getJobPoster(locale, jobPosterId, function (jobPosterResponse) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
68
        JobApplicationAPI.populateApplicationWithJobPosterContent(jobPosterResponse);
69
70
        //After all application form elements have been created, populate with saved content
71
        var userId = UserAPI.getSessionUserAsJSON().user_id;
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
72
        DataAPI.getJobApplicationByJobAndUser(jobPosterId, userId, function (request) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
73
            JobApplicationAPI.populateApplicationWithSavedApplicationContent(request, jobPosterId);
74
        })
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
75
76
    });
77
78
    // New Subpage Hero Scripts
79
80
    Utilities.getHeroElements();
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
81
82
    var applicationHeroTitle = document.getElementById("applicationHeroTitle");
83
    var applicationHeroMetadata = document.getElementById("applicationHeroMetadata");
84
    applicationHeroTitle.classList.remove("hidden");
85
    applicationHeroTitle.setAttribute("aria-hidden", "false");
86
    applicationHeroMetadata.classList.remove("hidden");
87
88
    // Mobile Menu Overflow Release
89
    document.body.style.overflowY = "visible";
90
91
    // Google Analytics
92
93
    // ga('set', 'page', '/apply/'+jobPosterId);
94
    // ga('send', 'pageview');
95
96
};
97
98
JobApplicationAPI.localizeCreateJobApplication = function () {
99
    if (siteContent) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable siteContent is declared in the current environment, consider using typeof siteContent === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
100
        // document.getElementById('createJobApplicationTitle').innerHTML = siteContent.createJobApplicationWindowTitle;
101
        // document.getElementById('createJobApplicationConfirmationTitle').innerHTML = siteContent.createJobApplicationWindowTitle;
102
        // document.getElementById('jobApplicationPositionLabel').innerHTML = siteContent.createJobApplicationJobTitleLabel;
103
        // document.getElementById('createJobApplicationSubmitButton').innerHTML = siteContent.submitApplication;
104
105
        //Localize confirmation page at same time
106
        document.getElementById('createJobApplicationConfirmationPositionLabel').innerHTML = siteContent.createJobApplicationConfirmationPositionLabel;
107
        document.getElementById('createJobApplicationConfirmationTrackingReminder').innerHTML = siteContent.jobApplicationConfirmationTrackingReminder;
108
        document.getElementById('createJobApplicationConfirmationContinueButton').innerHTML = siteContent.continueToDashboard;
109
    }
110
};
111
112
JobApplicationAPI.populateApplicationWithJobPosterContent = function (jobPosterResponse) {
113
    var jobPoster = JobPostAPI.populateJobObject(JSON.parse(jobPosterResponse));
0 ignored issues
show
Bug introduced by
The variable JobPostAPI seems to be never declared. If this is a global, consider adding a /** global: JobPostAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
114
115
    document.getElementById('jobApplicationPostition').innerHTML = jobPoster.title;
116
    JobApplicationAPI.populateApplicationWithQuestionContent(jobPoster.questions);
117
118
    //Create Evidence Panels
119
    JobApplicationAPI.createEvidencePanelsOnPage(jobPoster.core_competencies, "essential", "applicationEssentialEvidenceMenu", "applicationEssentialEvidenceFormWrapper");
120
121
    //TODO: create applicationAssetEvidence wrapper divs
122
    JobApplicationAPI.createEvidencePanelsOnPage(jobPoster.developing_competencies, "asset", "applicationAssetEvidenceMenu", "applicationAssetEvidenceFormWrapper");
123
124
    //Utilities.setEvidenceUiEventListeners();
125
    Utilities.setFormLabelHandler();
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
126
    Utilities.formRequirementLabelHandler();
127
128
    //TODO: call Utilities function to set up triggers
129
};
130
131
JobApplicationAPI.createEvidencePanelsOnPage = function (criteria, criteriaType, evidenceMenuId, evidenceFormWrapperId) {
132
    var evidenceMenu = document.getElementById(evidenceMenuId);
133
    var evidenceFormWrapper = document.getElementById(evidenceFormWrapperId);
134
    // evidenceMenu.innerHTML = "";
135
    var evidenceMenuItems = evidenceMenu.querySelectorAll(".applicant-evidence__desktop-menu-item");
136
    for (var i = 0; i < evidenceMenuItems.length; i++) {
137
        evidenceMenuItems[i].parentElement.removeChild(evidenceMenuItems[i]);
138
    }
139
    evidenceFormWrapper.innerHTML = "";
140
    var menuFragment = document.createDocumentFragment();
141
    var panelsFragment = document.createDocumentFragment();
142
143
    var firstCriteriaId = false;
0 ignored issues
show
Unused Code introduced by
The variable firstCriteriaId seems to be never used. Consider removing it.
Loading history...
144
145
    for (var i = 0; i < criteria.length; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 136. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like i was already defined.
Loading history...
146
        var criterion = criteria[i];
147
        var criteriaId = criterion.id;
148
        var criteriaName = criterion.value;
149
        if (criterion.description) {
150
            var criteriaDescription = criterion.description;
151
        } else {
152
            var criteriaDescription = criterion.description = "";
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable criteriaDescription already seems to be declared on line 150. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like criteriaDescription was already defined.
Loading history...
153
        }
154
155
        //Save first criteria for later
156
        if (i === 0) {
157
            firstCriteriaId = criteriaId;
158
        }
159
160
        var menuItem = EvidenceAPI.instantiateApplicationEvidenceMenuItem(criteriaId, criteriaType, criteriaName)
0 ignored issues
show
Bug introduced by
The variable EvidenceAPI seems to be never declared. If this is a global, consider adding a /** global: EvidenceAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
161
        var panelItem = EvidenceAPI.instantiateApplicationEvidencePanel(criteriaId, criteriaType, criteriaName, criteriaDescription);
0 ignored issues
show
Bug introduced by
The variable criteriaDescription seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
162
163
        menuFragment.appendChild(menuItem);
164
        panelsFragment.appendChild(panelItem);
165
    }
166
    evidenceMenu.appendChild(menuFragment);
167
    evidenceFormWrapper.appendChild(panelsFragment);
168
};
169
170
JobApplicationAPI.populateApplicationWithUserContent = function (user) {
171
    document.getElementById('createJobApplicationName').innerHTML = user.name;
172
};
173
174
JobApplicationAPI.populateApplicationWithSavedApplicationContent = function (jobApplicationRequestResponse, jobPosterId) {
175
    if (jobApplicationRequestResponse.status === 200) {
176
177
        var jobApplication = JSON.parse(jobApplicationRequestResponse.response);
178
179
        var jobPosterApplication = jobApplication.job_poster_application;
180
181
        //Store metadata
182
        document.getElementById("jobApplicationJobApplicationId").value = jobPosterApplication.job_poster_application_id;
183
        document.getElementById("jobApplicationJobPosterId").value = jobPosterApplication.application_job_poster_id;
184
        document.getElementById("jobApplicationUserId").value = jobPosterApplication.user_id;
185
        document.getElementById("jobApplicationJobApplicationStatusId").value = jobPosterApplication.job_poster_application_status_id;
186
187
        //Load saved skill declarations using application id
188
        SkillDeclarationAPI.loadSavedSkillDeclarationsForJobApplication(jobApplication.job_poster_application.job_poster_application_id);
0 ignored issues
show
Bug introduced by
The variable SkillDeclarationAPI seems to be never declared. If this is a global, consider adding a /** global: SkillDeclarationAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
189
        MicroReferenceAPI.loadSavedMicroReferencesForJobApplication(jobApplication.job_poster_application.job_poster_application_id);
0 ignored issues
show
Bug introduced by
The variable MicroReferenceAPI seems to be never declared. If this is a global, consider adding a /** global: MicroReferenceAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
190
        SkillSampleAPI.loadSavedSkillSamplesForJobApplication(jobApplication.job_poster_application.job_poster_application_id);
0 ignored issues
show
Bug introduced by
The variable SkillSampleAPI seems to be never declared. If this is a global, consider adding a /** global: SkillSampleAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
191
192
        //Set saved question answer content
193
        var application_question_answers = jobApplication.application_question_answers;
194
        for (var i = 0; i < application_question_answers.length; i++) {
195
            var value = application_question_answers[i];
196
            //find appropriate question textarea
197
            var inputElement = document.querySelector('.application-form__open-question-item[data-question-id="' + value.job_poster_question_id + '"] textarea');
198
            //if textarea exists, set value with saved value
199
            if (inputElement) {
200
                inputElement.value = value.answer;
201
            }
202
        }
203
    } else if (jobApplicationRequestResponse.status === 404) {
204
        //An application for this job and user doesn't exist yet, so create a new draft application
205
206
        var status = 1; //draft status id
207
208
        var user = UserAPI.getSessionUserAsJSON();
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
209
        var newApplication = new JobApplicationAPI.JobApplication(null, jobPosterId, user.user_id, status, []);
210
        DataAPI.createJobApplication(newApplication, function (request) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
211
            if (request.status === 200) {
212
                //Draft application was successfully created - save application id
213
                document.getElementById("jobApplicationJobApplicationId").value = JSON.parse(request.response).job_poster_application_id;
214
            } else {
215
                window.alert("Application could not be created.");
216
            }
217
        });
218
    }
219
};
220
221
/**
222
 *
223
 * @param {JobPostAPI.JobPosterQuestion} jobPosterQuestions
224
 * @return {undefined}
225
 */
226
JobApplicationAPI.populateApplicationWithQuestionContent = function (jobPosterQuestions) {
227
228
    var questionSectionWrapper = document.getElementById('createJobApplicationOpenEndedQuestionsWrapper');
229
230
    //REMOVE existing children (from previous application)
231
    questionSectionWrapper.innerHTML = '';
232
    var fragment = document.createDocumentFragment();
233
    for (var i = 0; i < jobPosterQuestions.length; i++) {
234
235
        var element = JobApplicationAPI.makeQuestionAnswerHtmlElement(jobPosterQuestions[i]);
236
        fragment.appendChild(element);
237
    }
238
    questionSectionWrapper.appendChild(fragment);
239
};
240
241
/**
242
 *
243
 * @param {JobPostAPI.JobPosterQuestion} jobPosterQuestion
244
 * @param {int} questionNumber - this is the nth question on the page
245
 * @return {Element} Job Application Question Answer Wrapper element
246
 */
247
JobApplicationAPI.makeQuestionAnswerHtmlElement = function (jobPosterQuestion) {
248
    var item = document.getElementById("jobApplicationQuestionAnswerTemplate").cloneNode(true);
249
    item.setAttribute("id", "");
250
    item.classList.remove("template");
251
252
    item.setAttribute("data-question-id",jobPosterQuestion.id);
253
    item.querySelector(".application-form__open-question").innerHTML = jobPosterQuestion.question;
254
    item.querySelector(".application-form__open-question-description").innerHTML = jobPosterQuestion.description;
255
256
    Utilities.addSuffixToElementId(item, "jobApplicationAnswerInput", "_" + jobPosterQuestion.id);
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
257
    return item;
258
};
259
260
/**
261
 * Saves the current Job Application.
262
 * Call onSuccess if application is saved successfully
263
 *
264
 * @param {function} onSuccess
265
 * @return {undefined}
266
 */
267
JobApplicationAPI.saveJobApplication = function (onSuccess) {
268
269
    var jobApplicationId = document.getElementById('jobApplicationJobApplicationId').value;
270
    var jobPosterId = document.getElementById('jobApplicationJobPosterId').value;
271
272
    //get all Question answers
273
    var applicationQuestionAnswers = [];
274
    var questionAnswerSection = document.getElementById('createJobApplicationOpenEndedQuestionsWrapper');
275
    var questionAnswerWrappers = questionAnswerSection.getElementsByClassName('application-form__open-question-item');
276
    for (var i = 0; i < questionAnswerWrappers.length; i++) {
277
        var questionId = questionAnswerWrappers[i].getAttribute("data-question-id");
278
        var answer = questionAnswerWrappers[i].getElementsByTagName('textarea')[0].value;
279
        var question = questionAnswerWrappers[i].querySelector(".application-form__open-question").innerHTML;
280
281
        var questionAnswer = new JobApplicationAPI.ApplicationQuestionAnswer(
282
                null, questionId, question, answer);
283
        applicationQuestionAnswers.push(questionAnswer);
284
    }
285
286
    var applicationStatus = 1; //draft status
287
    var userId = UserAPI.getSessionUserAsJSON().user_id;
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
288
    var jobApplication = new JobApplicationAPI.JobApplication(jobApplicationId, jobPosterId, userId, applicationStatus, applicationQuestionAnswers);
289
290
    DataAPI.saveJobApplicationByJobAndUser(jobApplication, jobPosterId, userId, function (request) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
291
        if (request.status === 200) {
292
            if (onSuccess) {
293
                onSuccess();
294
            }
295
        } else {
296
            var message = JSON.parse(request.response).message;
297
            window.alert(message);
298
        }
299
    });
300
};
301
302
JobApplicationAPI.showCreateJobConfirmation = function (jobTitle) {
303
    var stateInfo = {pageInfo: 'create_job_application_confirmation', pageTitle: 'Talent Cloud: New Job Application Confirmed'};
304
    document.title = stateInfo.pageTitle;
305
    history.pushState(stateInfo, stateInfo.pageInfo, '#CreateJobApplicationConfirmation/' + encodeURI(jobTitle));
0 ignored issues
show
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
306
307
    TalentCloudAPI.hideAllContent();
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
308
    window.scrollTo(0, 0);
309
310
    document.getElementById('createJobApplicationConfirmationPostition').innerHTML = jobTitle;
311
312
    var createJobApplicationSection = document.getElementById('createJobApplicationConfirmationSection');
313
    createJobApplicationSection.classList.remove('hidden');
314
315
    // New Subpage Hero Scripts
316
317
    Utilities.getHeroElements();
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
318
319
    var applicationHeroTitle = document.getElementById("applicationHeroTitle");
320
    applicationHeroTitle.classList.remove("hidden");
321
    applicationHeroTitle.setAttribute("aria-hidden", "false");
322
323
    // Mobile Menu Overflow Release
324
    document.body.style.overflowY = "visible";
325
326
};
327
328
JobApplicationAPI.showPreviousApplicationSection = function (jobPosterId) {
329
    JobApplicationAPI.shiftApplicationSection(-1, jobPosterId);
330
};
331
332
JobApplicationAPI.showNextApplicationSection = function (jobPosterId) {
333
    JobApplicationAPI.shiftApplicationSection(1, jobPosterId);
334
};
335
336
JobApplicationAPI.shiftApplicationSection = function (shift, jobPosterId) {
337
338
    window.scrollTo(0, 0);
339
    var progressItems = document.querySelectorAll(".application-progress__item");
340
341
    for (var i = 0; i < progressItems.length; i++) {
342
        if (!progressItems[i].classList.contains("inactive")) {
343
            //This item is not inactive, therefore it is the current section
344
            var shiftedIndex = i + shift;
345
            if (shiftedIndex < progressItems.length && shiftedIndex >= 0) {
346
                //as long as this would shift us to a valid index, show the new section
347
348
                var newSection = progressItems[shiftedIndex].getAttribute("data-application-section");
349
                JobApplicationAPI.showApplicationSection(newSection, jobPosterId);
350
            }
351
            break; //Ensuer this loop doesn't continue executing after we've switched sections
352
        }
353
    }
354
};
355
356
JobApplicationAPI.showApplicationSection = function (applicationSection, jobPosterId) {
357
    //Hide all application-sections except for selected one
358
    var applicationSections = document.querySelectorAll(".application-section");
359
    for (var i = 0; i < applicationSections.length; i++) {
360
        var section = applicationSections[i];
361
        if (section.getAttribute("data-application-section") === applicationSection) {
362
            section.classList.remove("hidden");
363
        } else {
364
            section.classList.add("hidden");
365
        }
366
    }
367
368
    //Set progress tracking bar to match
369
    var progressItems = document.querySelectorAll(".application-progress__item");
370
    for (var i = 0; i < progressItems.length; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 359. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like i was already defined.
Loading history...
371
        var item = progressItems[i];
372
        if (item.getAttribute("data-application-section") === applicationSection) {
373
            item.classList.remove("inactive");
374
            item.setAttribute("aria-hidden", "false");
375
        } else {
376
            item.classList.add("inactive");
377
            item.setAttribute("aria-hidden", "true");
378
        }
379
    }
380
381
    //TODO: select focus properly
382
383
    // Google Analytics
384
385
    ga('set', 'page', '/apply/' + jobPosterId + '/' + applicationSection);
386
    ga('send', 'pageview');
387
388
};
389
390
JobApplicationAPI.submitJobApplication = function (jobPosterId) {
391
    if (jobPosterId && jobPosterId.length > 0 && UserAPI.hasSessionUser()) {
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
392
        var userId = UserAPI.getSessionUserAsJSON().user_id;
393
394
        //Verify attestation is checked before submitting
395
        var attestationChecked = document.getElementById("applicationAttestation");
396
        var attestationError = document.getElementById("applicationAttestationError");
397
398
        //Submit only if attestation checked
399
        if (attestationChecked.checked !== true) {
400
            //Show message and don't submit if attestation not checked
401
            attestationError.classList.remove("hidden");
402
        } else {
403
            //Hide old attestation error message
404
            attestationError.classList.add("hidden");
405
406
            //Load current job appliction to verify its ready for submission
407
            DataAPI.getFullJobApplicationByJobAndUser(jobPosterId, userId, function (request) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
408
                if (request.status === 200) {
409
                    var fullJobApplication = JSON.parse(request.response);
410
411
                    //TODO: validate fullJobApplication
412
413
                    //TODO: validate that application is still in draft status.
414
                    if (parseInt(fullJobApplication.job_poster_application.job_poster_application_status_id) === 1) {
415
                        DataAPI.submitJobApplication(fullJobApplication.job_poster_application.job_poster_application_id, function (request) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
416
                            if (request.status === 200) {
417
                                var jobTitle = document.getElementById('jobApplicationPostition').innerHTML;
418
                                JobApplicationAPI.showCreateJobConfirmation(jobTitle);
419
                            } else {
420
                                //TODO: post message
421
                                window.alert(request.response);
422
                            }
423
                        });
424
                    } else {
425
                        window.alert("You cannot edit an application that has already been submitted.")
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
426
                    }
427
                }
428
            });
429
        }
430
    }
431
};
432